package com.zqxq.lottery.service.jczq.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.entity.bo.jczq.JczqWorldCupBO;
import com.zqxq.lottery.entity.o2o.jczq.JczqGrandO2O;
import com.zqxq.lottery.entity.po.jczq.JczqGrandPO;
import com.zqxq.lottery.entity.po.jczq.JczqWorldCupPO;
import com.zqxq.lottery.entity.vo.jczq.JczqGrandVO;
import com.zqxq.lottery.entity.vo.jczq.JczqWorldCupVO;
import com.zqxq.lottery.mapper.jczq.JczqGrandMapper;
import com.zqxq.lottery.mapper.jczq.JczqWorldCupMapper;
import com.zqxq.lottery.service.jczq.IJczqGrandService;
import com.zqxq.lottery.service.jczq.IJczqWorldCupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 说    明：   竞猜足球战绩榜
 * 创 建 人：	一刀·胡
 * 创建时间：	2018/7/13 16:58
 * 修 改 人：
 * 修改日期：
 **/
@Service
@Slf4j
public class JczqGrandServiceImpl extends ServiceImpl<JczqGrandMapper, JczqGrandPO> implements IJczqGrandService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public JczqGrandVO queryUserGrand(Long userId) {
        JczqGrandVO vo = new JczqGrandVO();
        JczqGrandPO po = this.baseMapper.queryUserGrand(userId);
        if(null != po){
            vo = JczqGrandO2O.toVO(po);
            List<Integer> overs = this.baseMapper.getOverData(po);
            if(overs.size()>=7){
                Integer cnt = 10000;
                String count = stringRedisTemplate.opsForValue().get("GRAND_COUNT");
                if(StrUtils.isNotEmpty(count)){
                    cnt = Integer.parseInt(count);
                    log.info("GRAND_COUNT:"+cnt);
                }
                DecimalFormat df = new DecimalFormat("0.00");
                Integer _div = overs.get(0)+cnt;
                vo.setOverOrder(df.format((float)overs.get(1)*100/_div));
                vo.setOverPrize(df.format((float)overs.get(2)*100/_div));
                vo.setOverMaxPrize(df.format((float)overs.get(3)*100/_div));
                vo.setOverWin(df.format((float)overs.get(4)*100/_div));
                vo.setOverHit(df.format((float)overs.get(5)*100/_div));
                vo.setOverContribution(df.format((float)overs.get(6)*100/_div+0.01));
                vo.setContribution(df.format(po.getPay().doubleValue()*0.18));
            }
        }
        return vo;
    }


}
